package com.satan.controller;

import com.satan.entity.response.ResCode;
import com.satan.entity.response.ResultEntity;
import com.satan.service.SysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName SysUserRoleController
 * @Description TODO
 * @date 2023/11/24 21:52
 * @Version 1.0
 */
@RestController
@RequestMapping("/user/role")
public class SysUserRoleController {
    @Autowired
    private SysUserRoleService sysUserRoleService;
    /**
     * 用户角色授权
     * @param userId
     * @param roleIds
     * @return
     */

    @PostMapping("/grant/{userId}")
    @PreAuthorize("hasAuthority('system:user:role')")
        public ResultEntity grantRole(@PathVariable("userId") Long userId, @RequestBody Long[] roleIds){
        boolean b=sysUserRoleService.grantRole(userId,roleIds);
        if (b){
            return ResultEntity.success(null);
        }else {
            return ResultEntity.fail(ResCode.GRANT_ERROR);
        }
    }

}
